﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using dbPoll_Application.Models;

namespace dbPoll_Application.ViewModels
{
    public class QuestionResponseViewModel
    {
        public int pollID { get; set; }
        public int questionNumber { get; set; }
        public int numberOfQuestions { get; set; }
        public String questionType { get; set; }
        public MultipleChoiceQuestion MCQuestion { get; set; }
        public ShortResponseQuestion SAQuestion { get; set; }
        public String SAQResponse { get; set; }
        public List<int> MCQResponses { get; set; }
        public MultiSelectList optionList { get; private set; }
        public String feedback { get; set; }
        public List<String> messages { get; set; }

        public QuestionResponseViewModel(MultipleChoiceQuestion MCQuestion, int questionNumber, int pollID, int numberOfQuestions, List<String> messages)
        {
            this.MCQuestion = MCQuestion;
            this.questionNumber = questionNumber;
            this.numberOfQuestions = numberOfQuestions;
            this.pollID = pollID;
            this.optionList = GetResponses(null);
            this.questionType = "MCQ";
            this.messages = messages;
        }

        public QuestionResponseViewModel(ShortResponseQuestion SAQuestion, int questionNumber, int pollID, int numberOfQuestions, List<String> messages, String questionType)
        {
            this.SAQuestion = SAQuestion;
            this.questionNumber = questionNumber;
            this.numberOfQuestions = numberOfQuestions;
            this.pollID = pollID;
            this.questionType = "SAQ";
            this.messages = messages;
        }


        public MultiSelectList GetResponses(int[] selectedValues)
        {
            List<QuestionOption> options = new List<QuestionOption>();

            foreach (var option in MCQuestion.options)
                {
                    options.Add(option);
                }

                return new MultiSelectList(options, "optionNumber", "answer", selectedValues);
        }

    }
}
